package ru.urfc.portal.operations;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.ejb.Stateless;

import ru.urfc.portal.model.radio.DeviceStateChange;

@Stateless
public class DeviceStateChangesFilter {

	public List<DeviceStateChange> filter(List<DeviceStateChange> items) {
		List<DeviceStateChange> result = new ArrayList<DeviceStateChange>();
		List<DeviceStateChange> sortedItems = new ArrayList<DeviceStateChange>(items);
		Collections.sort(sortedItems);
		Long previousStateCode = null;
		for (DeviceStateChange item: sortedItems) {
			Long itemCode = item.getState().getCode();
			if (itemCode != previousStateCode) {
				previousStateCode = itemCode;
				result.add(item);
			}
		}
		return result;
	}

}
